package com.ozner.WaterPurifier.RoWifi;

import android.util.Log;

import com.ozner.util.ByteUtil;
import com.ozner.util.Convert;
import com.ozner.util.Helper;

import java.util.Date;

/**
 * description: RoWifiDeviceInfo:ro机wifi模式下装置信息
 * autour: ozner_67
 * date: 2017/8/1 10:03
 * e-mail: xinde.zhang@cftcn.com
 */

public class RoWifiDeviceInfo {
    private static final String TAG = "RoWifiDeviceInfo";
    /**
     * wifi mac
     */
    public String mac;
    /**
     * 机型
     */
    public String deviceType;
    /**
     * 机号
     */
    public String deviceNumber;
    /**
     * 蓝牙MAC
     */
    public String bleMac;
    public int TDS2;
    public int TDS1;
    /**
     * 水机RTC时间
     */
    public Date RTC = new Date(70, 0, 0, 0, 0, 0);

    public long filterARemain;
    public long filterBRemain;
    public long filterCRemain;
    public long filterATotal;
    public long filterBTotal;
    public long filterCTotal;
    /**
     * 总流量
     */
    public long totalFlow;
    /**
     * 激活状态
     */
    public int activeCode;
    public int filterAPercent;
    public int filterBPercent;
    public int filterCPercent;


    public void fromBytes(byte[] data) {
        if (data == null || data.length < 118) {
            return;
        }
        try {
            byte[] macBytes = new byte[6];
            System.arraycopy(data, 4, macBytes, 0, 6);
            this.mac = Helper.splitBy(Convert.ByteArrayToHexString(macBytes), ":", 2);//new String(data, 4, 6);
            this.deviceType = new String(data, 12, 10).trim();
            this.deviceNumber = new String(data, 22, 16).trim();
            byte[] bleBytes = new byte[6];
            System.arraycopy(data, 65, bleBytes, 0, 6);
            this.bleMac = Helper.splitBy(Convert.ByteArrayToHexString(bleBytes), ":", 2);
            this.TDS2 = ByteUtil.getShort(data, 71);
            this.TDS1 = ByteUtil.getShort(data, 73);

            this.RTC = new Date(data[80] + 2000 - 1900, data[81] - 1, data[82], data[83], data[84], data[85]);

            this.filterARemain = ByteUtil.getUInt(data, 86);
            this.filterBRemain = ByteUtil.getUInt(data, 90);
            this.filterCRemain = ByteUtil.getUInt(data, 94);
            this.filterATotal = ByteUtil.getUInt(data, 98);
            this.filterBTotal = ByteUtil.getUInt(data, 102);
            this.filterCTotal = ByteUtil.getUInt(data, 106);
            this.totalFlow = ByteUtil.getUInt(data, 110);
            this.activeCode = ByteUtil.getShort(data, 114);
            this.filterAPercent = data[116];
            this.filterBPercent = data[117];
            this.filterCPercent = data[118];
        } catch (Exception ex) {
            Log.e(TAG, "fromBytes_ex: " + ex.getMessage());
        }
    }

    @Override
    public String toString() {
        return "RoWifiDeviceInfo{" +
                "mac='" + mac + '\'' +
                ", deviceType='" + deviceType + '\'' +
                ", deviceNumber='" + deviceNumber + '\'' +
                ", bleMac='" + bleMac + '\'' +
                ", TDS2=" + TDS2 +
                ", TDS1=" + TDS1 +
                ", RTC=" + RTC +
                ", filterARemain=" + filterARemain +
                ", filterBRemain=" + filterBRemain +
                ", filterCRemain=" + filterCRemain +
                ", filterATotal=" + filterATotal +
                ", filterBTotal=" + filterBTotal +
                ", filterCTotal=" + filterCTotal +
                ", totalFlow=" + totalFlow +
                ", activeCode=" + activeCode +
                ", filterAPercent=" + filterAPercent +
                ", filterBPercent=" + filterBPercent +
                ", filterCPercent=" + filterCPercent +
                '}';
    }
}
